package cn.edu.hstc.wm.service;

import java.util.Timer;
import java.util.TimerTask;

import android.app.IntentService;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

/**
 * @ClassName: UpdateService
 * @Description: 后台升级服务
 * 
 * @ModificationHistory
 */
public class UpdateService extends IntentService {

	public UpdateService(String name) {
		super(name);
	}

	private static final String TAG = UpdateService.class.getName();
	private Handler mHandler;

	private static final int CHECK_UP = 0x00;

	@Override
	protected void onHandleIntent(Intent intent) {

		mHandler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				if (msg.what == CHECK_UP) {
					UpdateManager.getUpdateManager(UpdateService.this).checkUpdate(true);
				}
			}

		};

		Timer timer = new Timer();
		TimerTask task = new TimerTask() {

			@Override
			public void run() {
				while (true) {
					mHandler.sendEmptyMessage(CHECK_UP);
					mHandler.postDelayed(this, 1000);
				}
			}
		};
		timer.schedule(task, 10000);
	}

}
